package hao.bk.searchMap;

import java.util.List;

import hao.bk.royalmap.ExtendedTextView;
import hao.bk.royalmap.RoyalMapActivity;
import hao.bk.royalmap.R;
import hao.bk.sql.bo.Typeshop;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * adapter: tùy biến cho danh sách các loại cửa hàng bao gồm 3 thành phần cho một dòng: 1.
 * ImageView: biểu diễn logo cửa hàng 2.
 * Đại diện cho sự lựa chọn loại cửa hàng
 * 
 * @author Haodv
 * 
 */

public class LocalTypeshopAdapter extends ArrayAdapter<Typeshop> {
	private RoyalMapActivity context;
	private List<Typeshop> typeshopList;
	
	public LocalTypeshopAdapter (RoyalMapActivity context, int resource,
			List<Typeshop> typeshopList) {
		super(context, resource, typeshopList);
		this.context = context;
		this.typeshopList = typeshopList;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		Typeshop rowItem = getItem(position);

		LayoutInflater mInflater = context.getLayoutInflater();
		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.local_typeshop_list_item, null);
			holder = new ViewHolder();
			holder.typeshopName = (TextView) convertView
					.findViewById(R.id.local_typeshop_name);
			holder.numberShop = (ExtendedTextView) convertView
					.findViewById(R.id.local_shop_number_in_typeshop);
		
			holder.numberFavoriteShop = (ExtendedTextView) convertView
					.findViewById(R.id.local_number_favorite_shop);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.typeshopName.setText(rowItem.getName());
		holder.typeshopName.setTypeface(RoyalMapActivity.fontSegoeB);
		//holder.typeshopName.setText("Trượt băng vinpeal");
		holder.numberShop.setText("Số lượng: "); //test
		holder.numberFavoriteShop.setText("Yêu thích: "); //test
		//holder.typeShopFavoriteIv.setBackground();
		//holder.provinceName.setTextSize(ScreenUtils.getDialogItemFontSize());
		AbsListView.LayoutParams param = new AbsListView.LayoutParams(
				LayoutParams.MATCH_PARENT, 100);
		convertView.setLayoutParams(param);

		return convertView;
	}

	@Override
	public Typeshop getItem(int position) {
		return typeshopList.get(position);
	}

	@Override
	public int getCount() {
		return typeshopList.size();
	}

	/* private view holder class */
	private class ViewHolder {
		private TextView typeshopName;
		private ExtendedTextView numberShop;
		private ExtendedTextView numberFavoriteShop;
		
	}
}

